#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
	unsigned int i;
	ssize_t len;
	int fd;
	char c;
	char *buf;

	if (argc != 4) {
		printf("not good format\n");
		return 1;
	}

	for (i = 0; i < argc; i++)
		printf("%s\n", argv[i]);
	
	c = atoi(argv[1]);
	len = atoi(argv[2]);
	fd = open(argv[3], O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
	if (-1 == fd) {
		printf("open failed!\n");
		return 1;
	}
	lseek(fd, len, SEEK_SET);
	write(fd, "", 1);

	buf = mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
	if (MAP_FAILED == buf) {
		printf("open failed!\n");
		return 1;
	}

	for (i = 0; i < len; i++)
		buf[i] = c;

	munmap(buf, len);
	close(fd);
	return 0;
}

